Skip to content

Conversation

@will-moore
Copy link
Collaborator

@will-moore will-moore commented Jun 26, 2025

Add support for importing OME-Zarr labels as regular OMERO Masks, with binary data in the DB.

Based on code from https://github.com/IDR/idr0156-szabo-tadcnd/blob/main/scripts/create_rois.py

Use --labels argument to include labels.

Screenshot shows colours and Shape text values read from Labels exported with omero-cli-zarr:

Screenshot 2025-06-26 at 15 09 15

@jburel
Copy link
Member

jburel commented Jun 26, 2025

Do you have some 5D examples?
We have https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.2/6001240.zarr but version 0.2 is not supported by the pixel buffer
The "registration" does not work with labels, It works without
i.e.

s3://idr/zarr/v0.2/6001240.zarr/labels/0/.zattrs
Traceback (most recent call last):
  File "/home/omero/register.py", line 705, in <module>
    main()
  File "/home/omero/register.py", line 702, in main
    register_image(conn, uri, args.name, transport_params, endpoint=endpoint, uri_parameters=params, do_labels=args.labels)
  File "/home/omero/register.py", line 497, in register_image
    image, rnd_def = create_image(conn, img_attrs, uri, image_name, families, models, transport_params, endpoint, uri_parameters, do_labels)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/omero/register.py", line 362, in create_image
    create_labels(conn, image, f"{labels_url}{labels_path}/", transport_params=transport_params)
  File "/home/omero/register.py", line 312, in create_labels
    axes = label_image["multiscales"][0]["axes"]
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'axes'

We need to decide which version we support.
e.g 0.4+ similar to zarr-pixel-buffer

@jburel
Copy link
Member

jburel commented Jul 18, 2025

Note that the PR introduced the need for new dependencies
Easiest option is to install ome-zarr and omero-rois

Attempting to import the image https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr

python register.py https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr --labels
leads to

labels_attrs {'labels': ['0']}
Traceback (most recent call last):
  File "/home/omero/register.py", line 760, in <module>
    main()
  File "/home/omero/register.py", line 754, in main
    obj = register_image(conn, uri, args.name, transport_params, endpoint=endpoint, uri_parameters=params, do_labels=args.labels)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/omero/register.py", line 500, in register_image
    image, rnd_def = create_image(conn, img_attrs, uri, image_name, families, models, transport_params, endpoint, uri_parameters, do_labels)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/omero/register.py", line 363, in create_image
    create_labels(conn, image, f"{labels_url}{labels_path}/", transport_params=transport_params)
  File "/home/omero/register.py", line 320, in create_labels
    labels_nd = da.from_zarr(array_path)
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/omero/workspace/OMERO-server/.venv3/lib64/python3.11/site-packages/dask/array/core.py", line 3796, in from_zarr
    z = zarr.open_array(store=store, path=component, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/omero/workspace/OMERO-server/.venv3/lib64/python3.11/site-packages/zarr/creation.py", line 645, in open_array
    init_array(
  File "/home/omero/workspace/OMERO-server/.venv3/lib64/python3.11/site-packages/zarr/storage.py", line 455, in init_array
    _init_array_metadata(
  File "/home/omero/workspace/OMERO-server/.venv3/lib64/python3.11/site-packages/zarr/storage.py", line 536, in _init_array_metadata
    shape = normalize_shape(shape) + dtype.shape
            ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/omero/workspace/OMERO-server/.venv3/lib64/python3.11/site-packages/zarr/util.py", line 84, in normalize_shape
    raise TypeError("shape is None")

Same issue when issuing directly the uri (which makes sense) i.e.

python register.py s3://idr/zarr/v0.4/idr0062A/6001240.zarr --endpoint https://uk1s3.embassy.ebi.ac.uk --nosignrequest --labels

@jburel
Copy link
Member

jburel commented Jul 21, 2025

Tested independently of this work
The approach taken to "read the labels" does not yet work for v4 with labels

@will-moore
Copy link
Collaborator Author

will-moore commented Jul 31, 2025

Merged origin/main in...

Test with e.g:

$ python register.py --target 21520 https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr --labels

@will-moore
Copy link
Collaborator Author

will-moore commented Jul 31, 2025

With example above:

$ python register.py --target 21520 https://uk1s3.embassy.ebi.ac.uk/bia-idr-integration/S-BIAD1961/experimentA/RP-TMA/RP-TMA-3_ROI01_multichannel.zarr/experimentA_backup/RP-TMA/RP-TMA-3_ROI01_multichannel.zarr/ --labels

Gives error:

/Users/wmoore/Desktop/BIONGFF/omero-import-utils/metadata/register.py:116: RuntimeWarning: overflow encountered in scalar add
  for i in range(1, labels_nd.max() + 1):

The label data ( in that example looks like

labels_data [[[[[  0   0   0 ...   0   0   0]
    [  0   0   0 ...   0   0   0]
    [  0   0   0 ...   0   0   0]
    ...
    [  0   0   0 ... 255 255 255]
    [  0   0   0 ... 255 255 255]
    [  0   0   0 ... 255 255 255]]]]]

@dominikl
Copy link
Collaborator

dominikl commented Sep 2, 2025

This would actually be really useful to have for https://github.com/IDR/idr0173-breiter-alphasynuclein. Could we port that to omero-cli-zarr too?

@will-moore
Copy link
Collaborator Author

Moved to ome/omero-cli-zarr#180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants